package com.yueke.gemini.listener;

import com.yueke.gemini.entity.WeixinConfig;
import com.yueke.gemini.utils.Commons;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.InputStream;
import java.util.Properties;

public class InitConfigListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		Properties prop = new Properties();
		InputStream in = this.getClass().getResourceAsStream("/weixin.properties");
		try {
			prop.load(in);
			WeixinConfig weixinConfig =new WeixinConfig();
			weixinConfig.setAppid(prop.getProperty("appid").trim());
			weixinConfig.setGrant_type(prop.getProperty("grant_type").trim());
			weixinConfig.setResponse_type(prop.getProperty("response_type").trim());
			weixinConfig.setScope(prop.getProperty("scope").trim());
			weixinConfig.setSecret(prop.getProperty("secret").trim());
			Commons.weixinConfig=weixinConfig;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub

	}

}
